public class ArrayMod {

	static int findMinDiff(int a[], int b[])
	{
		int i=0, j=0;
		int m = a.length;
		int n = b.length;
		int min = Integer.MAX_VALUE;
		while(i<m && j<n)
		{
			//a[i] = b[j]
			if(a[i]==b[j])
				return 0;
			//a[i] < b[j]
			else
				if(a[i] < b[j])
				{
					if(min > Math.abs(a[i]-b[j]))
						min = Math.abs(a[i] - b[j]);
					i++;
				}

			//a[i] > b[j] 
				else
				{
					if(min > Math.abs(a[i]-b[j]))
						min = Math.abs(a[i] - b[j]);
					
					j++;
				}
		}

		
		while(i < m)
		{
			if(min > Math.abs(a[i]-b[n-1]))
				min = Math.abs(a[i]-b[n-1]);
			i++;
		}

		while(j < n)
		{
			if(min > Math.abs(b[j]-a[m-1]))
				min = Math.abs(b[j]-a[m-1]);
			j++;
		}
		return min;
	}	


	public static void main(String[] args) {
		int[] a = {100,120};
		int[] b = {9,10,11,12};
		System.out.println(findMinDiff(a,b));
	}
}